/**
 * Copyright 2009 Sergio Bossa
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.googlecode.actorom.support;

import com.googlecode.actorom.FailoverPolicy;
import com.googlecode.actorom.impl.core.failover.AllForOneFailoverSchemeFactory;
import com.googlecode.actorom.impl.core.failover.FailoverSchemeFactory;
import com.googlecode.actorom.impl.core.failover.NoFailoverSchemeFactory;
import com.googlecode.actorom.impl.core.failover.OneForOneFailoverSchemeFactory;
import net.jcip.annotations.ThreadSafe;

/**
 * Static factory class for creating available {@link com.googlecode.actorom.FailoverPolicy} objects.
 *
 * @author Sergio Bossa
 */
@ThreadSafe
public class FailoverPolicies {

    /**
     * Create a {@link com.googlecode.actorom.FailoverPolicy} that restarts only the killed or failed actor,
     * depending on its configured {@link com.googlecode.actorom.annotation.Restart} semantics.
     * @return
     */
    public static FailoverPolicy newOneForOnePolicy() {
        return new OneForOnePolicy();
    }

    /**
     * Create a {@link com.googlecode.actorom.FailoverPolicy} that restarts all killed or failed actors,
     * depending on their configured {@link com.googlecode.actorom.annotation.Restart} semantics.
     * @return 
     */
    public static FailoverPolicy newAllForOnePolicy() {
        return new AllForOnePolicy();
    }
    
    /**
     * Create a {@link com.googlecode.actorom.FailoverPolicy} that never tries to restart killed or failed actors.
     * @return 
     */
    public static FailoverPolicy newNoFailoverPolicy() {
        return new NoFailoverPolicy();
    }

    private static class NoFailoverPolicy implements FailoverPolicy {

        public FailoverSchemeFactory getFailoverSchemeFactory() {
           return new NoFailoverSchemeFactory();
        }
    }

    private static class OneForOnePolicy implements FailoverPolicy {

        public FailoverSchemeFactory getFailoverSchemeFactory() {
           return new OneForOneFailoverSchemeFactory();
        }
    }

    private static class AllForOnePolicy implements FailoverPolicy {

        public FailoverSchemeFactory getFailoverSchemeFactory() {
            return new AllForOneFailoverSchemeFactory();
        }
    }
}
